// this file makes use of jQuery's ajax functions.
// so make sure jQuery is already included

var webservice = 
{	
	functionPath: "../functions.php"
	,
	call:
		function(parameters, callback){
			$.post(webservice.functionPath, parameters,
				function(response)
				{
					if(typeof callback == 'function')
					{
						try
						  {
						  	callback(eval(response));
						  }
						catch(err)
						  {
						    callback(response);
						  }
						
					}
				}
			);
		},
		
	photos:
	{
		createGallery: function(authorId, callback)
		{
			//alert("it gets to funtions.js, alright…");
			webservice.call({"do": "InsertGallery", "authorId":authorId}, callback);
		},
		
		addPhotos: function(galleryId, fileListStr, callback)
		{
			webservice.call({ "do":"InsertGalleryPhotos", "galleryId":galleryId, "fileNames":fileListStr }, callback);
		},
		
		getGalleryImages: function(galleryId, parameters, callback)
		{
			if(arguments.length == 3 && typeof parameters != "function")
			{
				webservice.call({ "do":"GetGalleryPhotos", "galleryId":galleryId, "first":parameters.startingIndex, "last":parameters.lastIndex }, callback);
			}else if (arguments.length == 2 && typeof parameters == "function")
			{
				callback = parameters;
				webservice.call({ "do":"GetGalleryPhotos", "galleryId":galleryId }, callback);
			}else
			{
				alert("getGalleryImages: ERROR (Wrong number of arguments.)");
			}
		},
		
		getGalleryThumbsFor: function (galleryId, callback)
		{
			webservice.call({ "do":"GetGalleryThumbsFor", "galleryId":galleryId }, callback);
		},
		
		getGalleryThumbsWithSearch: function (searchTerm, callback)
		{
			webservice.call({ "do":"GetGalleryThumbsWithSearch", "searchTerm":searchTerm }, callback);
		},
		
		setNewGalleryOrder: function (galleryId, serializedOrder, callback)
		{
			webservice.call({ "do":"OrderGalleryPhotos", "galleryId":galleryId, "orderData":serializedOrder }, callback);
		},
		
		updatePhotoProperties: function (photoId, photoTags, photoPublic, callback)
		{
			webservice.call({ "do":"SavePhotoProperties", "photoId":photoId, "photoTags":photoTags, "photoPublic":photoPublic }, callback);
		},
		
		removeTag: function (tagId, callback)
		{
			webservice.call({ "do":"RemoveTag", "tagId":tagId }, callback);		
		},
		
		makeGuestCheck: function (newfilename, photoName, month, day, year, topText, bottomText, topSize, bottomSize, topColor, bottomColor, callback)
		{
			webservice.call({ "do":"MakeGuestCheck", "newfilename":newfilename, "photoName":photoName, "month":month, "day":day, "year":year, "topText":topText, "bottomText":bottomText, "topSize":topSize, "bottomSize":bottomSize, "topColor":topColor, "bottomColor":bottomColor }, callback);	
		},
		
		makeNewPhotographerLogin: function (email, callback)
		{
			webservice.call({ "do":"CreateNewPhotographerLogin", "email":email }, callback);	
		},
		
		getPhotographerList: function (callback)
		{
			webservice.call({ "do":"GetPhotographerList" }, callback);	
		},
		
		setPhotographerActiveStatus: function (id, status, callback)
		{
			webservice.call({ "do":"SetPhotographerActiveStatus", "id":id, "status":status }, callback);
		},
		
		login: function (email, password, callback)
		{
			webservice.call({ "do":"Login", "email":email, "password":password }, callback);
		},
		
		setPermanentPassword: function (email, password, callback)
		{
			webservice.call({ "do":"SetPermanentPassword", "email":email, "password":password }, callback);
		},
		
		saveGalleryData: function (galleryId, month, day, year, name, topText, bottomText, topColor, bottomColor, callback)
		{
			webservice.call({ "do":"SaveGalleryData", "galleryId":galleryId, "month":month, "day":day, "year":year, "name":name , "topText":topText, "bottomText":bottomText, "topColor":topColor, "bottomColor":bottomColor}, callback);
		},
		
		getAllCategories: function (callback)
		{
			webservice.call({ "do":"GetAllCategories" }, callback);
		},
		
		getCategoryById: function (categoryId, callback)
		{
			webservice.call({ "do":"GetCategoryById", "categoryId":categoryId }, callback);
		},
		
		saveGalleryCategory: function (galleryId, categoryId, callback)
		{
			webservice.call({ "do":"SaveGalleryCategory", "galleryId":galleryId, "categoryId":categoryId }, callback);
		},
		
		saveNewCategory: function (title, color, callback)
		{
			webservice.call({ "do":"SaveNewCategory", "title":title, "color":color }, callback);
		},
		
		getGalleriesByAuthorId: function (authorId, callback)
		{
			webservice.call({ "do":"GetGalleriesByAuthorId", "authorId":authorId }, callback);
		},
		
		getAllGalleries: function (callback)
		{
			webservice.call({ "do":"GetAllGalleries" }, callback);
		},
		
		getPublicGalleries: function (callback)
		{
			webservice.call({ "do":"GetPublicGalleries" }, callback);
		},
		
		getPublicGalleriesByCategory: function ( categoryId, callback)
		{
			webservice.call({ "do":"GetPublicGalleriesByCategory", "categoryId":categoryId }, callback);
		},
		
		getGalleryData: function (galleryId, callback)
		{
			webservice.call({ "do":"GetGalleryData", "galleryId":galleryId }, callback);
		},
		
		setGalleryPublicStatus: function (galleryId, status, callback)
		{
			webservice.call({ "do":"SetGalleryPublicStatus", "galleryId":galleryId, "status":status }, callback);
		},
		
		getPhotoData: function (photoId, callback)
		{
			webservice.call({ "do":"GetPhotoData", "photoId":photoId }, callback);
		},
		setGalleryName: function (galleryId, name, callback)
		{
			webservice.call({ "do":"SetGalleryName", "galleryId":galleryId, "name":name}, callback);
		},
		updatePhotoPublic: function (photoId, photoPublic, callback)
		{
			webservice.call({ "do":"UpdatePhotoPublic", "photoId":photoId, "photoPublic":photoPublic }, callback);
		},
	}

}
